package com.retain.system.shiro;

import com.retain.system.shiro.cache.ShiroCache;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;

/**
 * @author: LiuWei
 * @date: Create in 9:57 2018/10/17
 */
public class RedisCacheManager implements CacheManager {

    private long globExpire = 1800;

    public RedisCacheManager() {
    }

    public RedisCacheManager(Long globExpire) {
       this.globExpire = globExpire;
    }

    @Resource(name = "redisTemplateObj")
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return new ShiroCache(name, redisTemplate, globExpire);
    }
}
